﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;

namespace FwProject.Authorization
{
    public class FwProjectAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {

            var pages = context.GetPermissionOrNull(PermissionNames.Pages);

            if (pages == null)
            {
                pages = context.CreatePermission(PermissionNames.Pages, L("基础权限"));
            }
            var fwyg = pages.CreateChildPermission(PermissionNames.Fwyg, L("饭碗易购"));

            //var admin = pages.CreateChildPermission(PermissionNames.Admin, L("Admin管理权限"));
            var adminManager = fwyg.CreateChildPermission(PermissionNames.AdminManager, L("Admin管理权限"));
            var Factory = adminManager.CreateChildPermission(PermissionNames.FactoryManager, L("工厂权限"));
            #region 工厂管理
            Factory.CreateChildPermission(PermissionNames.Factory_AdminUser_All, L("跨工厂角色员工"));
            Factory.CreateChildPermission(PermissionNames.Factory_All, L("管理平台关联工厂"));
            Factory.CreateChildPermission(PermissionNames.User_All_View, L("查看所有用户(默认只能查看本工厂)"));

            Factory.CreateChildPermission(PermissionNames.Factory, L("工厂管理"));

            Factory.CreateChildPermission(PermissionNames.Factory_Index, L("查看工厂列表"));

            Factory.CreateChildPermission(PermissionNames.Factory_Create, L("添加工厂"));
            Factory.CreateChildPermission(PermissionNames.Factory_Edit, L("修改工厂"));
            Factory.CreateChildPermission(PermissionNames.Factory_Delete, L("删除工厂"));
            #endregion

            #region 饭碗易购-送碗APP


            #region 用户管理
            var user = fwyg.CreateChildPermission(PermissionNames.User, L("用户管理"));
            var userMenu = user.CreateChildPermission(PermissionNames.User_Menu, L("菜单权限"));
            userMenu.CreateChildPermission(PermissionNames.User_Index, L("查看用户"));
            userMenu.CreateChildPermission(PermissionNames.Pages_Users, L("用户"));
            userMenu.CreateChildPermission(PermissionNames.Factory_Self, L("管理所属工厂"));

            var userOperation = user.CreateChildPermission(PermissionNames.User_Operation, L("操作权限"));
            userOperation.CreateChildPermission(PermissionNames.User_Create, L("添加用户"));
            userOperation.CreateChildPermission(PermissionNames.User_Edit, L("修改用户"));
            userOperation.CreateChildPermission(PermissionNames.User_Delete, L("删除用户"));

            #endregion

            #region 角色权限
            var role = fwyg.CreateChildPermission(PermissionNames.Role, L("角色权限"));

            var roleMenu = role.CreateChildPermission(PermissionNames.Role_Menu, L("菜单权限"));
            roleMenu.CreateChildPermission(PermissionNames.Role_Index, L("查看角色权限"));
            roleMenu.CreateChildPermission(PermissionNames.Pages_Roles, L("角色"));
            var roleOperation = role.CreateChildPermission(PermissionNames.Role_Operation, L("操作权限"));
            roleOperation.CreateChildPermission(PermissionNames.Role_Create, L("添加权限"));
            roleOperation.CreateChildPermission(PermissionNames.Role_Edit, L("修改权限"));
            roleOperation.CreateChildPermission(PermissionNames.Role_Delete, L("删除权限"));
            roleOperation.CreateChildPermission(PermissionNames.Role_Distribution, L("分配权限"));
            #endregion

            #region 餐厅管理
            var restaurant = fwyg.CreateChildPermission(PermissionNames.Restaurant, L("餐厅管理"));

            var restaurantMenu = restaurant.CreateChildPermission(PermissionNames.Restaurant_Menu, L("菜单权限"));
            restaurantMenu.CreateChildPermission(PermissionNames.Restaurant_Index, L("查看餐厅列表"));
            var restaurantOperation = restaurant.CreateChildPermission(PermissionNames.Restaurant_Operation, L("操作权限"));
            restaurantOperation.CreateChildPermission(PermissionNames.Restaurant_Create, L("添加餐厅"));
            restaurantOperation.CreateChildPermission(PermissionNames.Restaurant_Edit, L("修改餐厅"));
            restaurantOperation.CreateChildPermission(PermissionNames.Restaurant_Delete, L("删除餐厅"));
            #endregion

            #region 汽车管理
            var car = fwyg.CreateChildPermission(PermissionNames.Car, L("汽车管理"));

            var carMenu = car.CreateChildPermission(PermissionNames.Car_Menu, L("菜单权限"));
            carMenu.CreateChildPermission(PermissionNames.Car_Index, L("查看汽车列表"));

            var carOperation = car.CreateChildPermission(PermissionNames.Car_Operation, L("操作权限"));
            carOperation.CreateChildPermission(PermissionNames.Car_Create, L("添加汽车"));
            carOperation.CreateChildPermission(PermissionNames.Car_Edit, L("修改汽车"));
            carOperation.CreateChildPermission(PermissionNames.Car_Delete, L("删除汽车"));
            #endregion

            #region 型号管理
            var typenumber = fwyg.CreateChildPermission(PermissionNames.TypeNumber, L("型号管理"));

            var typenumberMenu = typenumber.CreateChildPermission(PermissionNames.TypeNumber_Menu, L("菜单权限"));
            typenumberMenu.CreateChildPermission(PermissionNames.TypeNumber_Index, L("查看型号列表"));

            var typenumberOperation = typenumber.CreateChildPermission(PermissionNames.TypeNumber_Operation, L("操作权限"));
            typenumberOperation.CreateChildPermission(PermissionNames.TypeNumber_Create, L("添加型号"));
            typenumberOperation.CreateChildPermission(PermissionNames.TypeNumber_Edit, L("修改型号"));
            typenumberOperation.CreateChildPermission(PermissionNames.TypeNumber_Delete, L("删除型号"));
            #endregion

            #region 配送管理
            var distribution = fwyg.CreateChildPermission(PermissionNames.Distribution, L("配送管理"));

            var distributionMenu = distribution.CreateChildPermission(PermissionNames.Distribution_Menu, L("菜单权限"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_Loading, L("装车"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_Distribution, L("配送"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_Report, L("配送报表"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_GraphicReport, L("配送图形报表"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_Store, L("店存"));
            distributionMenu.CreateChildPermission(PermissionNames.Distribution_Menu_Monitor, L("车辆监控"));

            var distributionOperation = distribution.CreateChildPermission(PermissionNames.Distribution_Operation, L("操作权限"));
            distributionOperation.CreateChildPermission(PermissionNames.Distribution_Operation_LoadingEntry, L("装车录入"));
            distributionOperation.CreateChildPermission(PermissionNames.Distribution_Operation_Excel, L("Excel导出"));
            distributionOperation.CreateChildPermission(PermissionNames.Distribution_Operation_Supplement, L("加单补录"));
            distributionOperation.CreateChildPermission(PermissionNames.Distribution_Operation_Inventory, L("盘点店存"));
            distributionOperation.CreateChildPermission(PermissionNames.Distribution_Edit, L("配送单编辑"));
            distributionOperation.CreateChildPermission(PermissionNames.LoadCar_Examine, L("装车单审核"));
            distributionOperation.CreateChildPermission(PermissionNames.LoadCar_AntiExamine, L("配送单编辑"));
            #endregion

            #region 财务管理
            var finance = fwyg.CreateChildPermission(PermissionNames.Finance, L("财务管理"));

            var financeMenu = finance.CreateChildPermission(PermissionNames.Finance_Menu, L("菜单权限"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Receivable, L("应收"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Receipt, L("收款"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Preparatory, L("预收款"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Payment, L("缴款"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Deposit, L("押金"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Statement, L("对账单"));
            financeMenu.CreateChildPermission(PermissionNames.Finance_Menu_Basic, L("基础资料"));

            var financeOperation = finance.CreateChildPermission(PermissionNames.Finance_Operation, L("操作权限"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_MakingReceipt, L("制作收据"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ReceiptApproval, L("收据审批"));
            financeOperation.CreateChildPermission(PermissionNames.Settlement_Edit, L("收款单编辑"));
            financeOperation.CreateChildPermission(PermissionNames.Receipt_Examine, L("收款单审核"));
            financeOperation.CreateChildPermission(PermissionNames.Receipt_AnTiExamine, L("收款单反审核"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ReceiptDelete, L("收据删除"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ReceiptPrint, L("收据打印"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_DeliveryDetailsPrint, L("打印配送明细"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_StatementPrint, L("打印对账单"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_Assignment, L("分配收据"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_AddPaid, L("添加收款"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_AddAdvance, L("添加预收款"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ModifyAdvance, L("编辑预收款"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_DeleteAdvance, L("删除预收款"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ReturnAdvance, L("退回预收款"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_Payment, L("缴款交账"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_PaymentObsolete, L("缴款作废"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_Deposit, L("收押金"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_RetreatDeposit, L("退押金"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_CreateAccount, L("添加账户"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_ModifyAccount, L("编辑账户"));
            financeOperation.CreateChildPermission(PermissionNames.Finance_Operation_DeleteAccount, L("删除账户"));
            financeOperation.CreateChildPermission("ces", L("test"));
            #endregion

            #region App 操作权限
            var AppAction = fwyg.CreateChildPermission(PermissionNames.AppDriver, L("app操作管理"));
            var AppActionOperation = AppAction.CreateChildPermission(PermissionNames.AppDriver_Operation, L("操作权限"));
            AppActionOperation.CreateChildPermission(PermissionNames.AppDriver_Edit_Stock, L("店存修改"));
            #endregion
            #endregion
            #region 饭碗易购-商城APP

            var shopapp = pages.CreateChildPermission(PermissionNames.ShopApp, L("商城"));

            #region 商品
            var commodity = shopapp.CreateChildPermission(PermissionNames.Commodity, L("商品"));
            var commodityMenu = commodity.CreateChildPermission(PermissionNames.Commodity_Menu, L("菜单权限"));
            commodityMenu.CreateChildPermission(PermissionNames.Commodity_Management, L("商品管理"));
            commodityMenu.CreateChildPermission(PermissionNames.Commodity_Settings, L("属性设置"));
            commodityMenu.CreateChildPermission(PermissionNames.Commodity_Reviews, L("商品评论"));
            commodityMenu.CreateChildPermission(PermissionNames.Commodity_Label, L("标签管理"));
            #endregion

            #region 订单
            var orders = shopapp.CreateChildPermission(PermissionNames.Orders, L("订单"));
            var ordersMenu = orders.CreateChildPermission(PermissionNames.Orders_Menu, L("菜单权限"));
            ordersMenu.CreateChildPermission(PermissionNames.Orders_Management, L("订单管理"));
            ordersMenu.CreateChildPermission(PermissionNames.Orders_Apply, L("订单退货"));
            #endregion

            #region 活动促销
            var promotion = shopapp.CreateChildPermission(PermissionNames.Promotion, L("活动促销"));
            var promotionMenu = promotion.CreateChildPermission(PermissionNames.Promotion_Menu, L("菜单权限"));
            promotionMenu.CreateChildPermission(PermissionNames.Promotion_Management, L("促销活动管理"));
            promotionMenu.CreateChildPermission(PermissionNames.Coupon_Management, L("优惠券管理"));
            #endregion

            #region 营销
            var advertising = shopapp.CreateChildPermission(PermissionNames.Advertising, L("营销"));
            var advertisingMenu = advertising.CreateChildPermission(PermissionNames.Advertising_Menu, L("菜单权限"));
            advertisingMenu.CreateChildPermission(PermissionNames.Advertising_Management, L("广告管理"));
            advertisingMenu.CreateChildPermission(PermissionNames.Keyword_Setup, L("关键字设置"));
            advertisingMenu.CreateChildPermission(PermissionNames.Content_Management, L("内容管理"));
            advertisingMenu.CreateChildPermission(PermissionNames.Notice_Management, L("公告管理"));
            #endregion

            #region 供应商
            var supplier = shopapp.CreateChildPermission(PermissionNames.Supplier, L("供应商"));
            var supplierMenu = supplier.CreateChildPermission(PermissionNames.Supplier_Menu, L("菜单权限"));
            supplierMenu.CreateChildPermission(PermissionNames.Supplier_Management, L("供应商管理"));
            #endregion

            #region 意见反馈
            var feedback = shopapp.CreateChildPermission(PermissionNames.Feedback, L("意见反馈"));
            var feedbackMenu = feedback.CreateChildPermission(PermissionNames.Feedback_Menu, L("菜单权限"));
            feedbackMenu.CreateChildPermission(PermissionNames.Feedback_Index, L("查看意见反馈列表"));
            #endregion

            #region 系统设置
            var sysconfig = shopapp.CreateChildPermission(PermissionNames.SysConfig, L("系统设置"));
            var sysconfigMenu = sysconfig.CreateChildPermission(PermissionNames.SysConfig_Menu, L("菜单权限"));
            sysconfigMenu.CreateChildPermission(PermissionNames.RegionConfig, L("地区管理"));
            #endregion

            #region 角色权限
            var rolespower = shopapp.CreateChildPermission(PermissionNames.RolesPower, L("角色权限"));
            var rolespowerMenu = rolespower.CreateChildPermission(PermissionNames.RolesPower_Menu, L("菜单权限"));
            rolespowerMenu.CreateChildPermission(PermissionNames.RolesPower_Index, L("查看角色列表"));
            #endregion

            #endregion


            context.CreatePermission(PermissionNames.Pages_Tenants, L("租户"), multiTenancySides: MultiTenancySides.Host);
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, FwProjectConsts.LocalizationSourceName);
        }
    }
}
